﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiFLEXCreateCableCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Flexibles;
using EngineeringInternalExtension;
using System;
using System.Collections.ObjectModel;
using System.Resources;
using System.Windows;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;


namespace DnProcessSimulateCommands;

[TxPowerEngineeringCommandCategory]
public class CUiFLEXCreateCableCmd : TxButtonCommand
{
  private readonly CApCableEnabler m_enabler;
  private CUiFLEXCableEditorWindow _window;
  private CUiFLEXCableNewEditorWindow _newWindow;

  public CUiFLEXCreateCableCmd() => this.m_enabler = new CApCableEnabler();

  public virtual void Execute(object cmdParams)
  {
    if (((Collection<ITxObject>) TxApplication.ActiveSelection.GetItems()).Count == 1 && ((Collection<ITxObject>) TxApplication.ActiveSelection.GetItems())[0] is ITxCable && !(((Collection<ITxObject>) TxApplication.ActiveSelection.GetItems())[0] as ITxComponent).IsOpenForModeling && TxDoNotShowAgainMessageBox.Show(CApFLEXStringTable.CableNotInModelingMessage, CApFLEXStringTable.CableEditorTitle, "EDIT_CABLE", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, DialogResult.Yes) == DialogResult.No)
      return;
    if (TxFeatureManager.CheckFeature("CABLE_STIFFNESS_OPTIMIZER"))
    {
      if (this._newWindow == null)
      {
        this.OpenDialog();
        ((Window) this._newWindow).Closed += new EventHandler(this._window_Closed);
      }
      ((Window) this._newWindow).Show();
    }
    else
    {
      if (this._window == null)
      {
        this.OpenDialog();
        ((Window) this._window).Closed += new EventHandler(this._window_Closed);
      }
      ((Window) this._window).Show();
    }
  }

  private void OpenDialog()
  {
    bool flag = true;
    if (((Collection<ITxObject>) TxApplication.ActiveSelection.GetItems()).Count == 1)
    {
      ITxObject itxObject = ((Collection<ITxObject>) TxApplication.ActiveSelection.GetItems())[0];
      if (itxObject is ITxCable cable)
      {
        if (TxFeatureManager.CheckFeature("CABLE_STIFFNESS_OPTIMIZER"))
          this._newWindow = new CUiFLEXCableNewEditorWindow(this, cable, this.GetLicense());
        else
          this._window = new CUiFLEXCableEditorWindow(this, cable, this.GetLicense());
        this.m_enabler.IsCableDialogOpened = true;
        flag = false;
      }
      else if (TxFeatureManager.CheckFeature("CABLE_STIFFNESS_OPTIMIZER") && itxObject is ITxPointCloudLayer pointCloudLayer)
      {
        this._newWindow = new CUiFLEXCableNewEditorWindow(this, pointCloudLayer, this.GetLicense());
        this.m_enabler.IsCableDialogOpened = true;
        flag = false;
      }
      else if (itxObject is ITxComponent equipmentScope && equipmentScope.IsEquipment && equipmentScope.IsOpenForModeling && this.GetLicense())
      {
        if (TxFeatureManager.CheckFeature("CABLE_STIFFNESS_OPTIMIZER"))
          this._newWindow = new CUiFLEXCableNewEditorWindow(this, equipmentScope);
        else
          this._window = new CUiFLEXCableEditorWindow(this, equipmentScope);
        this.m_enabler.IsCableDialogOpened = true;
        flag = false;
      }
    }
    if (!flag)
      return;
    if (this.GetLicense())
    {
      if (TxFeatureManager.CheckFeature("CABLE_STIFFNESS_OPTIMIZER"))
        this._newWindow = new CUiFLEXCableNewEditorWindow(this);
      else
        this._window = new CUiFLEXCableEditorWindow(this);
      this.m_enabler.IsCableDialogOpened = true;
    }
    else
      TxMessageBoxEx.ShowNoLicenseError(base.Name);
  }

  public virtual ITxImage Image => (ITxImage) Images.CableCmdIcon;

  private void _window_Closed(object sender, EventArgs e)
  {
    this.m_enabler.IsCableDialogOpened = false;
    this._newWindow = (CUiFLEXCableNewEditorWindow) null;
    this._newWindow = (CUiFLEXCableNewEditorWindow) null;
    this._window = (CUiFLEXCableEditorWindow) null;
    this._window = (CUiFLEXCableEditorWindow) null;
  }

  public virtual string Category
  {
    get
    {
      return new ResourceManager("DnProcessSimulateCommands.StringTable", ((object) this).GetType().Assembly).GetString("CREATE_CABLES_CATEGORY");
    }
  }

  public virtual string Name
  {
    get
    {
      return new ResourceManager("DnProcessSimulateCommands.StringTable", ((object) this).GetType().Assembly).GetString("EDITOR_CABLES_NAME");
    }
  }

  public virtual string Bitmap
  {
    get
    {
      return new ResourceManager("DnProcessSimulateCommands.StringTable", ((object) this).GetType().Assembly).GetString("CREATE_CABLES_BITMAP");
    }
  }

  public virtual string Tooltip
  {
    get
    {
      return new ResourceManager("DnProcessSimulateCommands.StringTable", ((object) this).GetType().Assembly).GetString("EDITOR_CABLES_TOOLTIP");
    }
  }

  public virtual string Description
  {
    get
    {
      return new ResourceManager("DnProcessSimulateCommands.StringTable", ((object) this).GetType().Assembly).GetString("EDITOR_CABLES_DESCRIPTION");
    }
  }

  public virtual string LargeBitmap
  {
    get
    {
      return new ResourceManager("DnProcessSimulateCommands.StringTable", ((object) this).GetType().Assembly).GetString("CREATE_CABLES_BITMAP_LARGE");
    }
  }

  public virtual bool Connect() => true;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_enabler;

  private bool GetLicense() => TxCommandLicenser.CableLicense;
}
